/****************************************************
          File Name:14-2.h
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sat Jan 10 17:17:36 2015
*****************************************************/

#ifndef WINE_H_
#define WINE_H_

#include <iostream>
#include <string>

using std::string;
using std::cout;
using std::cin;
using std::endl;

class Pair
{
    private:
        int *wine_year;
        int *wine_bottles;
    public:
        Pair(int a, int b) {wine_year = new int(a); wine_bottles = new int(b);}
        Pair(const int *a, const int *b);
        ~Pair() {}

        int* & getbot() { return wine_bottles; }
        void set(int a, int b, int i);
        void put(int i);
};

Pair::Pair(const int *a, const int *b)
{
    size_t len_a = sizeof(a)/sizeof(int);
    size_t len_b = sizeof(b)/sizeof(int);

    wine_year = new int[len_a];
    wine_bottles = new int[len_b];

    for(int i=0; i<len_a; i++)
        wine_year[i] = a[i];
    for(int i=0; i<len_b; i++)
        wine_bottles[i] = b[i];
}

void Pair::set(int a, int b, int i)
{
    wine_year[i] = a;
    wine_bottles[i] = b;
}

void Pair::put(int i)
{
    cout << "\t" << wine_year[i] << "\t" << wine_bottles[i] << "\n";
}

class Wine: private Pair
{
    private:
        string wine_label;
        int number_of_year;
    public:
        Wine(const char *l, int y, const int yr[], const int bot[]);
        Wine(const char *l, int y);

        void GetBottles();
        string & Label() { return wine_label; }
        void Show();
        int sum();
};

Wine::Wine(const char *l, int y, const int *yr, const int *bot)
    : wine_label(l), number_of_year(y), Pair(yr,bot)
{
    
}

Wine::Wine(const char *l, int y) : wine_label(l), number_of_year(y), Pair(y,y) {}

void Wine::GetBottles()
{
    cout << "Enter " << wine_label << " data for "
        << number_of_year << " year(s):\n";

    for(int i=0; i<number_of_year; i++)
    {
        int year, number;
        cout << "Enter year: "; (cin >> year).get();
        cout << "Enter bottles for that year: "; (cin >> number).get();

        Pair::set(year, number, i);
    }
}

void Wine::Show()
{
    cout << "Wine: " << wine_label << endl;
    cout << "\tYear\tBottles" << endl;
    for(int i=0; i<number_of_year; i++)
        Pair::put(i);
}

int Wine::sum()
{
    int tmp = 0;
    for(int i=0; i<number_of_year; i++)
        tmp += Pair::getbot()[i];
    return tmp;
}

#endif
